<?php


namespace app\common\library;
use common;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class IDMan
{

    static function random_string_with_date($randstr_length = 6)
    {
        return date('ymdHis') . common::random_string($randstr_length, false);
    }

    static function user_id()
    {
        $s = time() . common::random_string(6);
        return md5($s);
    }

    static function is_user_id($s)
    {
        if (strlen($s) == 32 && ctype_alnum($s)) {
            return true;
        }
        return false;
    }

    static function bike_id($city_id, $sn)
    {
        return $city_id . $sn;
    }

    static function is_bike_id($s)
    {
        if (strlen($s) != 14)
            return false;

        $h = substr($s, 6);
        return self::is_bike_sn($h);
    }

    static function is_bike_sn($s)
    {
        if (strlen($s) != 8) {
            return false;
        }
        $batnums = ['2000', '1001','1000'];
        foreach ($batnums as $bat) {
            $pos = strpos($s, $bat);
            if ($pos === 0) {
                return true;
            }
        }
        return false;
    }

    static function is_bike_imei($s)
    {
        if (strlen($s) != 15 || strlen($s) != 9) {
            return false;
        }
        return true;
    }

    static function city_order_id($city_id)
    {
        if (empty($city_id)) {
            return self::order_id();
        }
        $s = $city_id . self::random_string_with_date();
        return $s;
    }

    static function is_city_order_id($s)
    {
        if (strlen($s) != 22 && strlen($s) != 24)
            return false;

        return true;
    }

    static function order_id()
    {
        $s = self::random_string_with_date();
        return $s;
    }

}
